$OpenBSD: patch-src_audio_c,v 1.2 2014/11/04 10:58:21 sthen Exp $
--- src/audio.c.orig	Thu May 15 12:59:25 2014
+++ src/audio.c	Mon Nov  3 21:02:56 2014
@@ -32,13 +32,48 @@
 
 extern char sc_device[];
 
+#ifdef HAVE_SNDIO
+struct sio_hdl *ahdl;
+#else
 int afd;
+#endif
 
 #define ABUFSIZE          4000
 
 void init_audio()
 {
+#ifdef HAVE_SNDIO
+    struct sio_par par;
+ 
+    if ((ahdl = sio_open(SIO_DEVANY, SIO_REC, 0)) == NULL)
+    {
+        fprintf(stderr, "Failed to open audio device\n");
+	exit(1);
+    }
 
+    sio_initpar(&par);
+    par.bits = 8;
+    par.sig = 0;
+    par.rchan = 1;
+    par.rate = 8000;
+    if (!sio_setpar(ahdl, &par) || !sio_getpar(ahdl, &par))
+    {
+        fprintf(stderr, "Couldn't set audio parameters\n");
+	exit(1);
+    }
+
+    if (par.bits != 8 || par.sig || par.rchan != 1 || par.rate != 8000)
+    {
+        fprintf(stderr, "Unsupported audio parameters\n");
+	exit(1);
+    }
+
+    if (!sio_start(ahdl))
+    {
+        fprintf(stderr, "Couldn't start audio device\n");
+	exit(1);
+    }
+#else
     char afile[40];		/* Audio device name */
     int sndfmt;			/* Encoding of audio from */
     int channels;		/* Number of channels to record */
@@ -71,12 +106,16 @@ void init_audio()
 	perror("8000 sps");
 	exit(errno);
     }
+#endif
 }
 
 int close_audio()
 {
-
+#ifdef HAVE_SNDIO
+    sio_close (ahdl);
+#else
     close(afd);
+#endif
 
     return (0);
 }
@@ -132,6 +171,23 @@ int rescale(int testvalue)
     return (testvalue);
 }
 
+#ifdef HAVE_SNDIO
+void read_abuf(unsigned char *p) {
+    size_t todo, n;
+
+    todo = ABUFSIZE;
+    while (todo > 0) {
+	n = sio_read(ahdl, p, todo);
+	if (n == 0) {
+	    fprintf(stderr, "Failed to read from audio device\n");
+	    exit(1);
+	}
+	p += n;
+	todo -= n;
+    }
+}
+#endif
+
 float get_audio_sample(void)
 {
 
@@ -144,10 +200,14 @@ float get_audio_sample(void)
     int i, k;
 
     for (k = 0; k < 4; k++) {
+#ifdef HAVE_SNDIO
+	read_abuf(abuf);
+#else
 	if ((rc = read(afd, abuf, ABUFSIZE)) == -1) {
 	    perror("audio read");
 	    exit(errno);
 	}
+#endif
 
 	for (i = 0; i < rc; i++)	// calculate average
 	{
